' ****** START INCLUDE Rgba Core:::RgbaBox(x1%, y1%, x2%, y2%, c&, a%b) ******
DIM r0%, g0%, b0%, a0%, r1%, g1%, b1%, a1%
DIM RgbaAreaBorder& = &h1

SUB SetRgb0(x#,y#)
    DIM c$
    c$ = RIGHT$("000000" + HEX$(POINT(x#,y#)), 6)
    r0% = VAL("0x" + LEFT$(c$,2))
    g0% = VAL("0x" + MID$(c$,3,2))
    b0% = VAL("0x" + RIGHT$(c$,2))
END SUB

SUB SetRgb1(c&,a%b)
    DIM c$
    c$ = RIGHT$("000000" + HEX$(c&), 6)
    r1% = VAL("0x" + LEFT$(c$,2))
    g1% = VAL("0x" + MID$(c$,3,2))
    b1% = VAL("0x" + RIGHT$(c$,2))
    a0% = 255 - a%b
    a1% = a%b
END SUB

SUB RgbaCorePset(x#,y#)
    PSET(x#,y#), _RGB( [{ (r0%*a0%)+(r1%*a1%) }/255], [{ (g0%*a0%)+(g1%*a1%) }/255], [{ (b0%*a0%)+(b1%*a1%) }/255] )
END SUB



SUB RgbaBox(x1#, y1#, x2#, y2#, c&, a%b)
    DIM x#, y# : SetRgb1(c&, a%b)
    FOR x# = FIX(MAX(MIN(x1#,x2#),0)) TO FIX(MIN(MAX(x1#,x2#), xMAX))
      FOR y#  = FIX(MAX(MIN(y1#,y2#),0)) TO FIX(MIN(MAX(y1#,y2#), yMAX))
        SetRgb0(x#,y#) : RgbaCorePset(x#,y#)
    NEXT y# : NEXT x#
END SUB
'  ****** END INCLUDE Rgba Core:::RgbaBox(x1%, y1%, x2%, y2%, c&, a%b) ******

_Title "FourPointed SineWavy Thing"
' Port to BASIC Anywhere Machine and mod by Charlie Veniot
' Using the development version of BAM (improvements to CIRCLE performance and inclusion of "RgbaBox"
' Changes made to the original program to improve performance in BAM, noted in the code with "🟠" comments

' Based on a QB64 program by b+ (found at https://qb64phoenix.com/forum/showthread.php?tid=162&pid=19357#pid19357)
' _Title "Mod for vince mod for b+" ' b+ 2023-09-03

Dim w, h
' 🟠 Screen with and height reduced by half, and 1 added to help Charlie with FOR statement "STEP math"
w = 321 
h = 321
Screen _NewImage(w, h, 32)
Dim i, t, x, y, p(1 To 4)
p(1) = &HFF0000: p(2) = &H009900: p(3) = &H0000FF: p(4) = &HAAFF00

DO
    t = t + 0.1
    ' 🟠 BAM does not support RGBA colours in the standard BASIC graphics statements; hence the custom "RgbaBox" function for rgba
   ' Line (0, 0)-(w, h), &H25000000, BF
    RgbaBox(0, 0, xMAX, yMAX, &h0, 33) ' 🟠 changed the opacity from 25 to 33
    For i = 1 To 4
        Color p(i)
        For x = 0 To w step 2 ' 🟠 added step 2 to cut the processing in half
            y = 50 * Sin(_Pi * x / w ) * Sin(1 * _Pi * x / w  + t + i * t * _Pi * 0.01) ' 🟠 replaced "100" by "50" for adjusted screen resolution
            ' 🟠 changed circle radius from 2 to 3
            circle (x, h / 2 + y), 3
            ' 🟠 commented out the following statement; seemed unnecessary
            ' y = 100 * Sin(_Pi * x / w) * Sin(1 * _Pi * x / w + t + i * t * _Pi * 0.01)
            circle (w / 2 + y, x), 3
        Next
    Next
    _Display
    ' 🟠 removed the "_LIMIT" statement; BAM is not fast enough to need that
LOOP